import com.google.gson.Gson
import com.salton123.ast.FunctionManager
import com.salton123.ast.SaveProp
import java.io.File

object Main {

    @JvmStatic
    fun main(args: Array<String>) {
//        testFunc()
        mainFunc()
    }

    fun testFunc() {

        val code = """
package tv.athena.live.api.channel

import com.yy.liveplatform.proto.nano.LpfChannel
import tv.athena.live.api.IDataCallback
import tv.athena.live.api.callback.Callback
import tv.athena.live.base.arch.IComponentApi

interface ChannelApi : IComponentApi {
    fun getRoomNotice(uid: Long, sid: Long, callback: IDataCallback<LpfChannel.GetNoticeResp>?)
}
""".trimIndent()
        val mFuncList = FunctionManager.getktAst("H:\\auto_test\\kast\\TestChannelApi.kt")
        print(mFuncList)
    }

    fun mainFunc() {
        val userDir = System.getProperty("user.dir")
        val parentDir = File(userDir).parent
        val rootPath = "$userDir${File.separator}javaapis${File.separator}"
        val savePath = "$parentDir${File.separator}apis${File.separator}"
        val fileList = File(rootPath).listFiles().filter { it.name.endsWith(".kt") }.map {
            SaveProp(
                it.name,
                rootPath,
                savePath,
                "com.demo.liveroom.autotest.AutoLivingViewModel",
                "2.2.1060.13-SNAPSHOT"
            )
        }
        val midFile = File("${savePath}MidPlatformUser.py")
        if (midFile.exists()) {
            midFile.delete()
        }
        midFile.parentFile.mkdirs()
        midFile.createNewFile()
        midFile.appendText("class MidPlatformUser:\n\n")
        fileList.forEach {
            val mKtAstProp = FunctionManager.getktAst(it.filePath + it.fileName)
            println(Gson().toJson(mKtAstProp))
            FunctionManager.saveToFile(it, mKtAstProp)
            midFile.appendText(FunctionManager.getCallApis(it, mKtAstProp.funcList))
        }
    }
}